package cn.gson.crm.control;

import java.math.BigDecimal;
import java.util.Date;

import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gson.crm.model.pojo.DetailRepair;
import cn.gson.crm.model.pojo.Repair;
import cn.gson.crm.service.LLJ_RepairService;

@Controller
public class LLJ_RepairControl {
	@Autowired
	private LLJ_RepairService LLJ_RepairService;

	@RequestMapping("/toRepair")
	public String toRepair(){
		return "llj/Repair";    
	} 
	
	/*  添加维修工单     */
	@RequestMapping("/addRepair")
	@ResponseBody     
	public String addRepair(){
		String judge="failed";
		Repair r=new Repair();
    	r.setRepairMoveId("流水工单号5");
    	r.setRepairDatetime(new Date());
    	r.setRepairType("产品销售");
    	r.setCustomerId(new BigDecimal(1));
    	r.setCustomerName("简称1");
    	r.setContId(new BigDecimal(1));
    	r.setContLinkMan("客户联系人");
    	r.setRepairTel("18725678291"); 
    	if(LLJ_RepairService.addRepairData(r).equals("success")){
    		judge="添加维修工单成功";   
    		Long getId=LLJ_RepairService.getNewId();
    		
        	Repair repair=LLJ_RepairService.findRepair(getId);
        	
    		DetailRepair d=new DetailRepair();
    		d.setDrId(getId);
        	d.setDrProduct("维修产品名称5");
        	d.setDrProductSequ("维修产品序列号");
        	d.setDrProductDate(new Date()); 
        	d.setDrProductSale(new Date());
        	d.setDrGuarantee(new BigDecimal(1));
        	d.setDrAttention("注意事项5");
        	d.setDrDeptName("部门名称5"); 
        	d.setDrSpeedProgress("进行中"); 
        	d.setRepair(repair);  
        	d.setDrFee(new BigDecimal(1444.00));  
        	
        	try {
				if(LLJ_RepairService.addRepairDetailData(d).equals("success")){
					judge="添加维修详情成功";
				}else{           
					judge="添加维修详情失败";
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}else{   
    		judge="添加维修工单失败";
    	}
		return judge;    
	}
                     	
}
